home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’97 / NewsTicker / source code / Internet Code / OTPollEndPoint.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-12  |  3.0 KB  |  108 lines  |  [TEXT/CWIE]

  1. #ifndef OTPOLLENDPOINT_H
  2. #define OTPOLLENDPOINT_H
  3. /*------------------------------------------------------------------------------
  4. #
  5. #    NewsTicker, my Hack for 1997
  6. #
  7. #    OTPollEndPoint.cp    -    A general OT Endpoint class., designed to be derived.
  8. #
  9. #        After you open the connection, calling its DoIdle routine will check for
  10. #        any incoming data, and if found, call a derived method (broken into
  11. #        lines, if desired).  Also, when the connection is broken, it will call a
  12. #        derived shutdown method.
  13. #
  14. #        Not to be treated as a great example of OT programming, but it works.
  15. #
  16. ------------------------------------------------------------------------------*/
  17.  
  18. //+++Inc - Includes for files not directly related to this project
  19. #include <OpenTransport.h>
  20. #include <OpenTptInternet.h>
  21. #include <Types.h>
  22.  
  23. #define keOTPEPaborted -1
  24.  
  25. //This is a "waiting" class
  26. class Idler;
  27.  
  28. class OTPollEndPoint
  29. {
  30.     protected:
  31.         Boolean            mfCancelled;
  32.         Boolean            mfDataWaiting;
  33.         Boolean            mfLostConnection;
  34.         Boolean            mfNeedsDisconnecting;
  35.         Boolean            mfDataInIsText;
  36.  
  37.         char    mfInComingData[4096];        //data being received
  38.         short    mfBytesReceived;
  39.  
  40.  
  41.         OTTimeout        mulResolveTimeout;
  42.         volatile EndpointRef        mpEndpoint;
  43.         MapperRef        mpMapperRef;
  44.  
  45.         enum    OutpointState    {    keBinding, keBindingDone,
  46.                                         keConnecting, keConnectingDone,
  47.                                         keDisconnecting, keDisconnectingDone,
  48.                                         keOrderlyDisconnecting, keOrderlyDisconnectingDone,
  49.                                         
  50.                                         keOpeningMapper, keOpeningMapperDone,
  51.                                         keResolving, keResolvingDone,
  52.                                         
  53.                                         keBailingOut    };
  54.         
  55.         OSErr                miAsyncErr;
  56.         OutpointState    meState;
  57.         union {
  58.             InetAddress    inet;
  59.         }                    mfDestAddress;
  60.      
  61.     protected:
  62.                         OTPollEndPoint        (const OTPollEndPoint& oRHS);
  63.         OTPollEndPoint&    operator=        (const OTPollEndPoint& oRHS);
  64.  
  65.         // Returns true if the endpoint has been cancelled. Also disconnects and destroys
  66.         // the endpoint if it has been cancelled.
  67.         Boolean        CheckCancelled    (Idler& oIdler);
  68.         
  69.         Boolean        EndPointValid    (void) const;
  70.         OSErr            DestroyEndPoint(void);
  71.         void            CheckOTError    (OTResult lError);
  72.         
  73.         OSErr            OpenEndpoint    (const char *protocol);
  74.         OSErr            ResolveAddress    (Idler& oIdler, const char* pszHost, InetHost& lHostsIPAddress);
  75.  
  76.         static pascal void        Notifier            (void* contextPtr, OTEventCode code,
  77.                                                             OTResult result, void* cookie);
  78.         void                             HandleNotify    (OTEventCode code, OTResult result, void* cookie);
  79.  
  80.         virtual OSErr    GetData ( void );
  81. //
  82. // This is the workhorse
  83. //
  84.         virtual void    HandleData            (char* thestring, short numchars);
  85. //
  86. // If we need to tell someone we've closed, override this
  87. //
  88.         virtual void    HandleShutdown    (void);
  89.         
  90.     public:
  91.                         OTPollEndPoint        (void);
  92.         virtual        ~OTPollEndPoint        (void);
  93.         
  94.         OSErr            Open                (Idler& oIdler, const char *address, short port);
  95.         OSErr            Close                (Idler* poIdler);
  96.  
  97.         void            Cancel            (void);
  98.         void            SetCancelFlag     (Boolean fCancel) { mfCancelled = fCancel; }
  99.  
  100.         virtual OSErr    SendData            (Idler& oIdler, const void *pData, long lSize);
  101.  
  102.         virtual void    DoIdle                (void);
  103.  
  104.  
  105. };
  106.  
  107. #endif        //OTPollEndPoint_H
  108.